package _07聊天系统;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class ChatServer {
    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(9999);

        while (true){
            Socket socket = serverSocket.accept();

            new Thread(new Runnable() {
                @Override
                public void run() {

                    try {
                        InputStream is = socket.getInputStream();
                        InputStreamReader isr =new InputStreamReader(is);
                        BufferedReader br = new BufferedReader(isr);
                        String readLine = br.readLine();
                        System.out.println(readLine);


                        Scanner sc = new Scanner(System.in);
                        System.out.print("请输入聊天信息");
                        String line = sc.nextLine();
                        PrintStream p = new PrintStream(socket.getOutputStream());
                        p.println(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
            }).start();





        }
    }
}
